<?php
App::uses('AppController', 'Controller');
/**
 * SysFronts Controller
 *
 * @property SysFront $SysFront
 * @property PaginatorComponent $Paginator
 */
class SysFrontsController extends AppController {

/**
 * Components
 *
 * @var array
 */
	public $components = array('Paginator');

/**
 * admin_index method
 *
 * @return void
 */
	public function admin_index() {
		$this->SysFront->recursive = 0;
		$this->set('sysFronts', $this->Paginator->paginate('SysFront',array('SysFront.sys_website_id'=>$this->Session->read('SITEID'))));
	}

/**
 * admin_view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function admin_view($id = null) {
		if (!$this->SysFront->exists($id)) {
			throw new NotFoundException(__('Invalid sys front'));
		}
		$options = array('conditions' => array('SysFront.' . $this->SysFront->primaryKey => $id));
		$this->set('sysFront', $this->SysFront->find('first', $options));
	}

/**
 * admin_add method
 *
 * @return void
 */
	public function admin_add() {
		if ($this->request->is('post')) {
			$this->SysFront->create();
			if ($this->SysFront->save($this->request->data)) {
				$this->Session->setFlash(__('The sys front has been saved.'));
				Cache::delete('nav_cache_sh', '_zmx_month_cache_');
				Cache::delete('nav_cache_bj', '_zmx_month_cache_');
				return $this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The sys front could not be saved. Please, try again.'));
			}
		}
		$sysWebsites = $this->SysFront->SysWebsite->find('list');
		$this->set(compact('sysWebsites'));
	}

/**
 * admin_edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function admin_edit($id = null) {
		if (!$this->SysFront->exists($id)) {
			throw new NotFoundException(__('Invalid sys front'));
		}
		if ($this->request->is(array('post', 'put'))) {
			if ($this->SysFront->save($this->request->data)) {
				$this->Session->setFlash(__('The sys front has been saved.'));
				Cache::delete('nav_cache_sh', '_zmx_month_cache_');
				Cache::delete('nav_cache_bj', '_zmx_month_cache_');
				return $this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The sys front could not be saved. Please, try again.'));
			}
		} else {
			$options = array('conditions' => array('SysFront.' . $this->SysFront->primaryKey => $id));
			$this->request->data = $this->SysFront->find('first', $options);
		}
		$sysWebsites = $this->SysFront->SysWebsite->find('list');
		$this->set(compact('sysWebsites'));
	}

/**
 * admin_delete method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function admin_delete($id = null) {
		$this->SysFront->id = $id;
		if (!$this->SysFront->exists()) {
			throw new NotFoundException(__('Invalid sys front'));
		}
		$this->request->onlyAllow('post', 'delete');
		if ($this->SysFront->delete()) {
			$this->Session->setFlash(__('The sys front has been deleted.'));
		} else {
			$this->Session->setFlash(__('The sys front could not be deleted. Please, try again.'));
		}
		return $this->redirect(array('action' => 'index'));
	}}
